﻿using AbpPcClient.WpfClient.Common;
using AbpPcClient.WpfClient.Extension;
using AbpPcClient.WpfClient.Models;
using Prism.Commands;
using Prism.Mvvm;
using Prism.Regions;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AbpPcClient.WpfClient.ViewModels
{
    public class MainViewModel:BindableBase, IConfigureService
    {
//    <DrawingImage xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
//      <DrawingImage.Drawing>
//        <GeometryDrawing Brush = "Black" Geometry="M21.79,13L16,16L17,18L13,17.25V21H11V17.25L7,18L8,16L2.21,13L3.21,11.27L1.61,8L5.21,7.77L6.21,6L9.63,9.9L8,5H10L12,2L14,5H16L14.37,9.9L17.79,6L18.79,7.73L22.39,7.96L20.79,11.19L21.79,13Z" />
//      </DrawingImage.Drawing>
//   </DrawingImage>
        public MainViewModel(IRegionManager regionManager)
        {
            IniMenu();
            NavigateCommand = new DelegateCommand<MenuBar>(Navigate);
            this.regionManager = regionManager;
            GoBackCommand = new DelegateCommand(() =>
            {
                if (journal!=null&&journal.CanGoBack) journal.GoBack();
            });
            GoForwardCommand = new DelegateCommand(() =>
            {
                if (journal != null && journal.CanGoForward) journal.GoForward();
            });
        }
        private void Navigate(MenuBar menuBar)
        {
            if (menuBar != null && !string.IsNullOrEmpty(menuBar.NameSpace))
            {
                try
                {
                    //将指定命名空间(我们这里是在Views文件夹下面的xaml)加载到 MainView中的MainViewRegion
                    regionManager.Regions[PrismManager.MainViewRegionName].RequestNavigate(menuBar.NameSpace,
                  back =>
                  {  //导航日志  前一步 后一步
                      journal = back.Context.NavigationService.Journal;
                  });
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
                
              
              
          
        }
        public DelegateCommand<MenuBar> NavigateCommand { get;private set; }
        public DelegateCommand GoBackCommand { get;private set; }  //上一步
        public DelegateCommand GoForwardCommand { get; private set; } //下一步
        private ObservableCollection<MenuBar> menuBars;
        private readonly IRegionManager regionManager;
        private  IRegionNavigationJournal journal;
        public ObservableCollection<MenuBar> MenuBars
        {
            get { return menuBars; }
            set { menuBars = value; RaisePropertyChanged(); }    
        }
        /// <summary>
        /// 初始化菜单
        /// </summary>
        public void IniMenu()
        {
            MenuBars = new ObservableCollection<MenuBar>();
            MenuBars.Add(new MenuBar() { Icon = "Home", Title = "首页", NameSpace = "IndexView" });
            MenuBars.Add(new MenuBar() { Icon = "AccountCheck", Title = "租户管理", NameSpace = "TenantManagerView" });
            // 
            MenuBars.Add(new MenuBar()
            {
                Icon = "AccountTie", //图标
                Title = "测试窗体", //标题
                NameSpace = "TestView"  //命名空间, 也可以理解为显示哪个窗体
            });
            MenuBars.Add(new MenuBar()
            {
                Icon = "AccountTie", //图标
                Title = "物资采购审批", //标题
                NameSpace = "WuZiCaiGou"  //命名空间, 也可以理解为显示哪个窗体
            });
            MenuBars.Add(new MenuBar()
            {
                Icon = "AccountTie", //图标
                Title = "物资领用审批", //标题
                NameSpace = "WuZiLingY"  //命名空间, 也可以理解为显示哪个窗体
            });
            MenuBars.Add(new MenuBar()
            {
                Icon = "AccountTie", //图标
                Title = "显示列表", //标题
                NameSpace = "WuZiList"  //命名空间, 也可以理解为显示哪个窗体
            });


        }

        public void Configure()
        {
            IniMenu();
            regionManager.Regions[PrismManager.MainViewRegionName].RequestNavigate("IndexView");
        }
    }
}
